home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 March / SOFM_Mar1995.bin / mac / General Interest / KeyQuencer 1.2.1 / Developer’s toolkit / Extension code / Action.c < prev    next >
Text File  |  1994-11-23  |  3KB  |  80 lines

  1. //==============================================================================
  2. // KEYQUENCER EXTENSIONS SAMPLE - VERSION 1.2.1 - NOVEMBER 1994
  3. // ⌐1994 Alessandro Levi Montalcini <LMontalcini@pmn.it>
  4. // Don╒t forget to send me any cool extensions you create!
  5. // This text looks best in monaco 9 font, 4 spaces per tab, no wrapping
  6. //
  7. // DOCUMENTATION IS AVAILABLE IN THE EXTENSION.H AND ACTION.H HEADERS
  8.  
  9. #include "Extension.h"
  10. #include "Action.h"
  11.  
  12. Handle    gTextResource;
  13.  
  14. //==============================================================================
  15. // THIS ROUTINE IS CALLED WHEN THE EXTENSION IS INVOKED BY A MACRO
  16.  
  17. short run(ParamsPtr params, MachineHandle mac, GluePtr glue)
  18. {
  19.     // This is where the extension does its work
  20.     // cur heap zone = active app heap, cur res file = unknown
  21.     // the extension file is closed, resources are not available
  22.     
  23.     StringPtr    string;
  24.     long        length;
  25.     short        index;
  26.     Str255        message;
  27.     
  28.     message[0] = 0;                                                        // clear message string
  29.     for(index=0; index<params->paramsCount; ++index)                    // scan all params
  30.     {
  31.         string = params->parameter[index];                                // get nth parameter
  32.         if(string[1]=='"' && string[0]>2)                                // check for quotes
  33.         {
  34.             if(message[0]>0) return kTellTooManyParams;                    // we only accept one parameter
  35.             BlockMoveData(&string[2], &message[1], (long)string[0]-2);    // copy text, strip quotes
  36.             message[0] = string[0]-2;
  37.         }
  38.         else if(EqualString("\pLOADED", string, false, true))            // check for "loaded" keyword
  39.         {
  40.             if(message[0]>0) return kTellTooManyParams;                    // again, no more than 1 param
  41.             if(gTextResource==0L)                                        // 'TEXT' 128 not found
  42.             {
  43.                 (*glue->DisplayMessage)("\ptext resource not found at startup.", true);
  44.                 return kExtGenericError;
  45.             }
  46.             length = GetHandleSize(gTextResource);                        // get text length
  47.             if(length>255) length = 255;                                // max length of our string
  48.             BlockMoveData(*gTextResource, &message[1], length);            // copy to message string
  49.             message[0] = (unsigned char)length;
  50.         }
  51.         else return kTellUnknownKeyword;                                // unknown keyword found
  52.     }
  53.     if(message[0]==0) return kTellNotEnoughParams;                        // didn't find required parameter
  54.     
  55.     (*glue->DisplayMessage)(message, false);                            // display our message
  56.     return kExtNoError;                                                    // we're done
  57. }
  58.  
  59. //==============================================================================
  60. // THIS ROUTINE IS CALLED ONCE AT STARTUP TIME
  61.  
  62. short init(MachineHandle mac, GluePtr glue)
  63. {
  64.     // This is only called once at startup time
  65.     // cur heap zone = sys heap, cur res file = extension res file
  66.     // you may load (and detach) resources and initialize your data
  67.     // glue is only available in recent versions, check for nil glue
  68.     
  69.     gTextResource = Get1Resource('TEXT', 128);                            // load resource
  70.     if(gTextResource)
  71.     {
  72.         HNoPurge(gTextResource);                                        // make it unpurgeable
  73.         DetachResource(gTextResource);                                    // res file will be closed soon
  74.     }
  75.     if(glue) (*glue->ShowStartupIcon)(128);                                // show our own icon (no glue was available in KQ 1.0)
  76.     return kExtNoError;                                                    // everything OK
  77. }
  78.  
  79. //==============================================================================
  80.